/*
 * EnterMineAndDigForNugget.java
 *
 * Created on March 27, 2007, 10:59 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package ai9hells.pgaibe.chapter2.westworldwithmessaging;

import ai9hells.pgaibe.common.fsm.State;
import ai9hells.pgaibe.common.messaging.Telegram;

/**
 *
 * @author andre.bandarra
 */
public class EnterMineAndDigForNugget extends State<Miner>{
    public static final State<Miner> INSTANCE = new EnterMineAndDigForNugget();
    /** Creates a new instance of EnterMineAndDigForNugget */
    private EnterMineAndDigForNugget() {
    }

    public boolean onMessage(Miner m, Telegram t) {
        return false;
    }

    public void enter(Miner m) {
        if (m.getLocation() != Locations.GOLDMINE){
            System.out.println(EntityNames.getNameOfEntity(m.getId())+": Walkin' to the goldmine");
            m.setLocation(Locations.GOLDMINE);
        }
    }

    public void execute(Miner m) {
        m.addGoldCarried(1);
        m.increaseFatigue();
        System.out.println(EntityNames.getNameOfEntity(m.getId())+": Pickin' up a nugget");        
        
        if (m.isPocketFull()){
            m.getStateMachine().changeState(VisitBankAndDepositGold.INSTANCE);
        }
        
        if (m.isThirsty()){
            m.getStateMachine().changeState(QuenchThirst.INSTANCE);
        }
    }

    public void exit(Miner m) {
        System.out.println(EntityNames.getNameOfEntity(m.getId())+": Ah'm leavin' the goldmine with mah pockets full o' sweet gold");
    }
    
}
